import 'package:date_format/date_format.dart';

/// Create： Zhang 4/6/21 2:18 PM
/// 描述：日期格式化
class DateFormatter {
  static const formatter_01 = [mm, '月', dd, "号 ", HH, ":", nn];
  static const formatter_02 = [yyyy, '-', mm, '-', dd];
  static const formatter_03 = [
    yyyy,
    '-',
    mm,
    '-',
    dd,
    " ",
    HH,
    ":",
    nn,
    ":",
    ss,
  ];
  static const formatter_04 = [yyyy, '-', mm];
  static const formatter_05 = [mm, '/', dd];
  static const formatter_06 = [mm, '月', dd, "日"];
  static const formatter_07 = [HH, ":", nn];

  ///日期格式化
  static String formatDateTime(
    DateTime date, {
    formatter = formatter_03,
  }) {
    return formatDate(date, formatter);
  }

  ///日期格式化
  static String format(
    int time, {
    formatter = formatter_01,
  }) {
    var date = DateTime.fromMillisecondsSinceEpoch(time);
    return formatDate(date, formatter);
  }

  ///获取日期是周几
  static String getWeek({
    required int year,
    required int month,
    required int day,
  }) {
    switch (formatDate(DateTime(year, month, day), [D])) {
      case "Mon":
        return "周一";
      case "Tue":
        return "周二";
      case "Wed":
        return "周三";
      case "Thur":
        return "周四";
      case "Fri":
        return "周五";
      case "Sat":
        return "周六";
      default:
        return "周日";
    }
  }
}
